<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_EnseignantRole extends Application_Model_ModelAbstract
{

    /**
     * Database var type varchar(45)
     *
     * @var string
     */
    protected $_IdEr;

    /**
     * Database var type varchar(8)
     *
     * @var string
     */
    protected $_EnseignantCin;

    /**
     * Database var type int(2)
     *
     * @var int
     */
    protected $_RoleIdRole;


    /**
     * Parent relation fk_enseignant_has_role_enseignant1
     *
     * @var Application_Model_Enseignant
     */
    protected $_Enseignant;

    /**
     * Parent relation fk_enseignant_has_role_role1
     *
     * @var Application_Model_Role
     */
    protected $_Role;


    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'id_er'=>'IdEr',
            'enseignant_cin'=>'EnseignantCin',
            'role_id_role'=>'RoleIdRole',
        ));

        $this->setParentList(array(
            'FkEnseignantHasRoleEnseignant1'=> array(
                    'property' => 'Enseignant',
                    'table_name' => 'Enseignant',
                ),
            'FkEnseignantHasRoleRole1'=> array(
                    'property' => 'Role',
                    'table_name' => 'Role',
                ),
        ));

        $this->setDependentList(array(
        ));
    }

    /**
     * Sets column id_er
     *
     * @param string $data
     * @return Application_Model_EnseignantRole
     */
    public function setIdEr($data)
    {
        $this->_IdEr = $data;
        return $this;
    }

    /**
     * Gets column id_er
     *
     * @return string
     */
    public function getIdEr()
    {
        return $this->_IdEr;
    }

    /**
     * Sets column enseignant_cin
     *
     * @param string $data
     * @return Application_Model_EnseignantRole
     */
    public function setEnseignantCin($data)
    {
        $this->_EnseignantCin = $data;
        return $this;
    }

    /**
     * Gets column enseignant_cin
     *
     * @return string
     */
    public function getEnseignantCin()
    {
        return $this->_EnseignantCin;
    }

    /**
     * Sets column role_id_role
     *
     * @param int $data
     * @return Application_Model_EnseignantRole
     */
    public function setRoleIdRole($data)
    {
        $this->_RoleIdRole = $data;
        return $this;
    }

    /**
     * Gets column role_id_role
     *
     * @return int
     */
    public function getRoleIdRole()
    {
        return $this->_RoleIdRole;
    }

    /**
     * Sets parent relation EnseignantCin
     *
     * @param Application_Model_Enseignant $data
     * @return Application_Model_EnseignantRole
     */
    public function setEnseignant(Application_Model_Enseignant $data)
    {
        $this->_Enseignant = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['cin'];
        }

        $this->setEnseignantCin($primary_key);

        return $this;
    }

    /**
     * Gets parent EnseignantCin
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Enseignant
     */
    public function getEnseignant($load = true)
    {
        if ($this->_Enseignant === null && $load) {
            $this->getMapper()->loadRelated('FkEnseignantHasRoleEnseignant1', $this);
        }

        return $this->_Enseignant;
    }

    /**
     * Sets parent relation RoleIdRole
     *
     * @param Application_Model_Role $data
     * @return Application_Model_EnseignantRole
     */
    public function setRole(Application_Model_Role $data)
    {
        $this->_Role = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id_role'];
        }

        $this->setRoleIdRole($primary_key);

        return $this;
    }

    /**
     * Gets parent RoleIdRole
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Role
     */
    public function getRole($load = true)
    {
        if ($this->_Role === null && $load) {
            $this->getMapper()->loadRelated('FkEnseignantHasRoleRole1', $this);
        }

        return $this->_Role;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_EnseignantRole
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_EnseignantRole());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_EnseignantRole::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdEr() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('id_er = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdEr()));
    }
}
